var t = require;
var e = module;
var o = exports;
var a,
    i =
        (this && this.__extends) ||
        ((a = function (t, e) {
            return (a =
                Object.setPrototypeOf ||
                ({ __proto__: [] } instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                })(t, e);
        }),
            function (t, e) {
                a(t, e);
                function o() {
                    this.constructor = t;
                }
                t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o());
            }),
    n =
        (this && this.__decorate) ||
        function (t, e, o, a) {
            var i,
                n = arguments.length,
                r = n < 3 ? e : null === a ? (a = Object.getOwnPropertyDescriptor(e, o)) : a;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, a);
            else
                for (var s = t.length - 1; s >= 0; s--)
                    (i = t[s]) && (r = (n < 3 ? i(r) : n > 3 ? i(e, o, r) : i(e, o)) || r);
            return n > 3 && r && Object.defineProperty(e, o, r), r;
        };
Object.defineProperty(o, "__esModule", { value: !0 });
var r = t("UIBase"),
    s = t("UIConfig"),
    c = t("UIManager"),
    p = t("GameEm"),
    l = cc._decorator,
    d = l.ccclass,
    u =
        (l.property,
            l.menu,
            (function (t) {
                i(e, t);
                function e() {
                    var e = (null !== t && t.apply(this, arguments)) || this;
                    e.canClose = !1;
                    return e;
                }
                e.prototype._onCloseAllTouchEnd = function () {
                    this.canClose && this.closeUI();
                };
                e.prototype.setBtnCoin = function (t) {
                    SpriteView.setBtnCoin(t, this._rewardBtnSprite.$Sprite);
                };
                e.prototype.onShowEnd = function () {
                    EVUIEffView.on(EVUIEffView.checkCostUI, this.updateBtnData.bind(this), this);
                    this.updateBtnData();
                    QAudio.play(QAudio.ui_popup);
                    this.openGuild();
                };
                e.prototype.updateBtnData = function () {
                    var t = this.ui_data.data;
                    this.setRewardDataView(t);
                    this._timeViewNode.active = !1;
                    switch (t.cost_item) {
                        case 10:
                            this.setBtnCoin(1);
                            this._countLab.$Label.string = "免费";
                            this.checkAdReward(t);
                            break;
                        case 6:
                            this.checkReward(t, 2);
                            break;
                        case 7:
                            this.checkReward(t, 3);
                    }
                };
                e.prototype.checkAdReward = function (t) {
                    this._timeViewNode.active = !0;
                    this.checkAdView(t);
                };
                e.prototype.checkAdView = function (t) {
                    var e = GameDataValue.getShopTimeCount(1, 0),
                        o = Date.now() - e,
                        a = t.time_cd || 0;
                    if (o >= (a *= 1e3)) {
                        this._timeViewNode.active = !1;
                        this.setBtnRender(this._btnBg, !0);
                    } else {
                        this._timeViewNode.active = !0;
                        this._timeViewNode.$TimeViewNode2.checkView(e, a, this.moveTimeCall.bind(this));
                        this.setBtnRender(this._btnBg, !1);
                    }
                };
                e.prototype.moveTimeCall = function (t) {
                    "1" == t && (this._timeViewNode.active = !1);
                };
                e.prototype.openGuild = function () {
                    if (!GuildCache.isOverOnceGuid(GuildCache.oncecheckId[2][1])) {
                        GuildCache.checkKey = GuildCache.oncecheckId[2][1];
                        GuildCache.overOnceGuid(GuildCache.oncecheckId[2][1]);
                        GuildCache.openGuildView();
                    }
                };
                e.prototype.checkReward = function (t, e) {
                    var o = GameDataValue.getShopKey(t.cost_item),
                        a = t.cost_num || 0;
                    if (o >= a && a > 0) {
                        this._countLab.$Label.string = o + "/" + a;
                        this.setBtnCoin(e);
                        this.setBtnRender(this._openBtn, !0);
                    } else {
                        var i = GameDataValue.getPropCount(p.PropKind.zhuanshi),
                            n = t.diamond_num || 0;
                        this._countLab.$Label.string = "" + n;
                        this.setBtnCoin(4);
                        i >= n ? this.setBtnRender(this._btnBg, !0) : this.setBtnRender(this._btnBg, !1);
                    }
                };
                e.prototype.setRewardDataView = function (t) {
                    var e = CacheDataManager.getRewardKind(this.ui_data.data.item_id).open_costume_rate.split("|");
                    switch (t.item_id) {
                        case 3:
                            SpriteView.setBoxBottom(1, this._boxBottom.$Sprite);
                            SpriteView.setBoxTop(1, this._boxTop.$Sprite);
                            this._rewardLay.$RateRewardNode.resetList(e);
                            break;
                        case 4:
                            SpriteView.setBoxBottom(2, this._boxBottom.$Sprite);
                            SpriteView.setBoxTop(2, this._boxTop.$Sprite);
                            this._rewardLay.$RateRewardNode.resetList(e);
                            break;
                        case 5:
                            SpriteView.setBoxBottom(3, this._boxBottom.$Sprite);
                            SpriteView.setBoxTop(3, this._boxTop.$Sprite);
                            this._rewardLay.$RateRewardNode.resetList(e);
                    }
                };
                e.prototype.setBtnRender = function (t, e) {
                    var o = t.getComponentsInChildren(cc.RenderComponent);
                    for (var a in o) CacheDataManager.setSpriteMat(o[a], e);
                };
                e.prototype._onOpenBtnTouchEnd = function () {
                    this.clickOpenBtn();
                };
                e.prototype.clickOpenBtn = function () {
                    var t = this.ui_data.data,
                        e = (this.ui_data.id, this.ui_data.kind, CacheDataManager.getRewardKind(this.ui_data.data.item_id));
                    switch (t.cost_item) {
                        case 10:
                            this.openAd(e, "20001", "4小时宝箱");
                            break;
                        case 6:
                            this.openBox(e, "20002", "过关宝箱");
                            break;
                        case 7:
                            this.openBox(e, "20003", "豪华宝箱");
                    }
                };
                e.prototype.openBox = function (t, e, o) {
                    var a = this,
                        i = this.ui_data.data,
                        n = GameDataValue.getShopKey(i.cost_item),
                        r = i.cost_num || 0,
                        l = this.ui_data.id,
                        d = this.ui_data.kind;
                    if (n >= r && r > 0) {
                        GameDataValue.setShopKey(i.cost_item, n - r);
                        var u = {
                            resId: e,
                            count: r,
                            type: this.ui_data.data.cost_item,
                            rewadJson: {},
                            tip: o,
                            tip2: "钥匙消耗"
                        };
                        c.default.open(s.UIID.UIBoxReward, {
                            rewardData: t,
                            id: l,
                            kind: d,
                            data: i,
                            logData: u,
                            costId: e,
                            tipStr: o
                        });
                        this.closeUI();
                    } else {
                        QReport.send(1 == l ? "220002" : "220003");
                        var h = GameDataValue.getPropCount(p.PropKind.zhuanshi),
                            f = i.diamond_num || 0;
                        h >= f
                            ? c.default.open(s.UIID.UIUseZs, {
                                cost: f,
                                cb: function () {
                                    GameDataValue.setPropCount(p.PropKind.zhuanshi, h - f);
                                    var n = { resId: e, count: f, type: 1, rewadJson: {}, tip: o, tip2: "钻石消耗" };
                                    c.default.open(s.UIID.UIBoxReward, {
                                        rewardData: t,
                                        id: l,
                                        kind: d,
                                        data: i,
                                        logData: n,
                                        costId: e,
                                        tipStr: o
                                    });
                                    a.closeUI();
                                }
                            })
                            : c.default.open(s.UIID.UIToast, { msg: "钻石不足" });
                    }
                };
                e.prototype.openAd = function (t, e, o) {
                    var a = this,
                        i = this.ui_data.id,
                        n = (this.ui_data.kind, this.ui_data.data),
                        r = GameDataValue.getShopTimeCount(1, i),
                        p = Date.now() - r,
                        l = n.time_cd || 0;
                    p >= (l *= 1e3)
                        ? BannerAd.Instance.ShowVideo(() => {
                            var r = { resId: e, count: 1, type: 4, rewadJson: {}, tip: o, tip2: "商店看广告购买" },
                                p = a.ui_data.id,
                                l = a.ui_data.kind;
                            c.default.open(s.UIID.UIBoxReward, {
                                rewardData: t,
                                id: p,
                                kind: l,
                                data: n,
                                logData: r,
                                costId: e,
                                tipStr: o
                            });
                            console.log("UIReward ----------------- 设置广告时间", l, p);
                            GameDataValue.setShopTimeCount(1, p, Date.now());
                            a.closeUI();
                        })
                        // AdView.showRewardVedioAd(
                        //       function (i) {
                        //           if (i) {
                        //               var r = {resId: e, count: 1, type: 4, rewadJson: {}, tip: o, tip2: "商店看广告购买"},
                        //                   p = a.ui_data.id,
                        //                   l = a.ui_data.kind;
                        //               c.default.open(s.UIID.UIBoxReward, {
                        //                   rewardData: t,
                        //                   id: p,
                        //                   kind: l,
                        //                   data: n,
                        //                   logData: r,
                        //                   costId: e,
                        //                   tipStr: o
                        //               });
                        //               console.log("UIReward ----------------- 设置广告时间", l, p);
                        //               GameDataValue.setShopTimeCount(1, p, Date.now());
                        //               a.closeUI();
                        //           }
                        //       },
                        //       "5",
                        //       "ui reward"
                        //   )
                        : c.default.open(s.UIID.UIToast, { msg: "冷却中" });
                };
                e.prototype.onCloseStart = function () {
                    CacheDataManager.updateCostDataView = !0;
                    EVUIEffView.offTarget(this);
                };
                return n([d], e);
            })(r.default));
o.default = u;
